//
//  SearchViewController.m
//  LOL_PalmarHelper
//
//  Created by dllo on 15/6/19.
//  Copyright (c) 2015年 hantao. All rights reserved.
//

#import "SearchViewController.h"

@interface SearchViewController ()

@end

@implementation SearchViewController



-(void)dealloc
{
    [_array1 release];
    [_array2 release];
    [_array3 release];
    [_allArray release];
    [_nameLaber release];
    [_nameTextField release];
    [_searchButton release];
    [_serverLabel release];
    [_serverLabel1 release];
    [_showLabel release];
    [super dealloc];



}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.navigationItem.title = @"召唤师查询";
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
//    
    
    
    self.nameLaber = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.origin.x + 10, self.view.bounds.origin.y + 10, self.view.bounds.size.width - 20, 50)];
    self.nameLaber.backgroundColor = [UIColor clearColor];
    self.nameLaber.text = @"召唤师名称";
    self.nameLaber.font = [UIFont systemFontOfSize:18];
    [self.view addSubview:self.nameLaber];
    [_nameLaber release];
    
    self.nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(self.nameLaber.frame.origin.x, self.nameLaber.frame.origin.y + self.nameLaber.frame.size.height + 5, self.nameLaber.frame.size.width, 45)];
    self.nameTextField.borderStyle = UITextBorderStyleNone;
    self.nameTextField.delegate = self;
    self.nameTextField.placeholder = @"召唤师名称";
    self.nameTextField.layer.cornerRadius = 5;
    self.nameTextField.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.nameTextField];
    [_nameTextField release];
    
    self.serverLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.nameTextField.frame.origin.x, self.nameTextField.frame.origin.y + self.nameTextField.frame.size.height + 10, self.nameTextField.frame.size.width, self.nameLaber.frame.size.height)];
    self.serverLabel.backgroundColor = [UIColor clearColor];
    self.serverLabel.text = @"服务器名称";
    self.serverLabel.font = [UIFont systemFontOfSize:18];
    [self.view addSubview:self.serverLabel];
    [_serverLabel release];
        
    self.serverLabel1 = [UIButton buttonWithType:UIButtonTypeCustom];
    self.serverLabel1.frame = CGRectMake(self.serverLabel.frame.origin.x, self.serverLabel.frame.origin.y + self.serverLabel.frame.size.height + 5, self.serverLabel.frame.size.width, self.nameTextField.frame.size.height);
    [self.serverLabel1 setTitle:@"选择大区" forState:UIControlStateNormal];
    [self.serverLabel1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.serverLabel1.backgroundColor = [UIColor whiteColor];
    self.serverLabel1.layer.cornerRadius = 5;
   
    [self.serverLabel1 addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.serverLabel1];
    
    self.searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.searchButton.frame = CGRectMake(self.serverLabel1.frame.origin.x, self.serverLabel1.frame.origin.y + self.serverLabel1.frame.size.height + 25, self.serverLabel1.frame.size.width, self.serverLabel1.frame.size.height);
    self.searchButton.backgroundColor = [UIColor greenColor];
    [self.searchButton setTitle:@"搜索" forState:UIControlStateNormal];
    self.searchButton.layer.cornerRadius = 5;
    [self.searchButton addTarget:self action:@selector(searchButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.searchButton];
    
//    self.showLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.searchButton.frame.origin.x, self.searchButton.frame.origin.y + self.searchButton.frame.size.height + 15, self.searchButton.frame.size.width, self.searchButton.frame.size.height)];
//    self.showLabel.backgroundColor = [UIColor whiteColor];
//    
//    [self.view addSubview:self.showLabel];
//    [_showLabel release];
    
    self.TView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, self.view.frame.size.width , self.view.frame.size.height)];
    self.TView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.TView];
    [_TView release];
    
    
    self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, self.view.frame.size.width - 150, self.view.frame.size.height - 400) style:UITableViewStylePlain];
//        self.table.center = self.view.center;
    
    [self.TView addSubview:self.table];
    
    self.table.backgroundColor = [UIColor clearColor];
    self.table.bounces = NO;
    self.table.showsVerticalScrollIndicator = NO;    self.table.delegate = self;
    self.table.dataSource = self;
    
    [_table release];

    
    self.array1 = [NSArray arrayWithObjects:@"艾欧尼亚 电信一", @"祖安 电信二", @"诺克萨斯 电信三", @"班德尔城 电信四", @"皮尔特沃夫 电信五", @"战争学院 电信六", @"巨神峰 电信七", @"雷瑟守备 电信八", @"裁决之地 电信九", @"黑色玫瑰 电信十", @"暗影岛 电信十一", @"钢铁烈阳 电信十二", @"均衡教派 电信十三", @"水晶之痕 电信十四", @"影流 电信十五", @"守望之海 电信十六", @"征服之海 电信十七", @"卡拉曼达 电信十八", @"皮城警戒 电信十九", nil];
    self.array2 = [NSArray arrayWithObjects:@"比尔吉沃特 网通一",@"德玛西亚 网通二", @"弗雷尔卓德 网通三", @"无畏先锋 网通四", @"恕瑞玛 网通五", @"扭曲丛林 网通六", @"巨龙之巢 网通七", nil];
    self.array3 = [NSArray arrayWithObjects:@"教育网专区 教育一", nil];
    
    self.allArray = [NSArray arrayWithObjects:self.array1,self.array2,self.array3, nil];
    
}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

    [self.view endEditing:YES];

    self.TView.frame = CGRectMake(0, self.view.bounds.size.height, self.view.frame.size.width , self.view.frame.size.height);
    self.table.frame = CGRectMake(0, self.view.bounds.size.height, self.view.frame.size.width - 150, self.view.frame.size.height - 400);


}



-(BOOL)textFieldShouldReturn:(UITextField *)textField
{

    [textField resignFirstResponder];

    return YES;
}


-(void)searchButtonAction
{
//    self.showLabel.text = [NSString stringWithFormat:@"%@    %@",self.show,self.nameTextField.text];
    
    [self.nameTextField resignFirstResponder];
    
    ServerNameViewController *ser = [[ServerNameViewController alloc] init];
    
    NSArray *a = [self.show componentsSeparatedByString:@" "];
    
    ser.playerName = self.nameTextField.text;
    ser.server = [a objectAtIndex:1];
    
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:ser];
    [self presentViewController:nav animated:YES completion:^{
        
        
    }];
    


}


-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{


    return [NSArray arrayWithObjects:@"电",@"网",@"教", nil];
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

   NSArray *arr = [self.allArray objectAtIndex:indexPath.section];
    self.show = [arr objectAtIndex:indexPath.row];
//    NSLog(@"////////%@",str);
    [self.serverLabel1 setTitle:self.show forState:UIControlStateNormal];
  
    self.TView.frame = CGRectMake(0, self.view.bounds.size.height, self.view.frame.size.width , self.view.frame.size.height);
    self.table.frame = CGRectMake(0, self.view.bounds.size.height, self.view.frame.size.width - 150, self.view.frame.size.height - 400);
    
}
-(void)buttonAction
{

    self.TView.frame = [[UIScreen mainScreen] bounds];
    self.table.frame = CGRectMake(self.view.frame.size.width / 4, self.view.bounds.size.height / 5, self.view.frame.size.width - (self.view.frame.size.width / 5) * 2, self.view.frame.size.height * 2 / 3);

}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        
        return @"电信区";
    }else if (section == 1)
    {
        
        return @"网通区";
    }else
    {
        return @"教育网专区";
    }
    
    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (section == 0) {
        return 19;
    }else if (section == 1) {
        
        return 7;
    }else{
        
        return 1;
    }
    
    
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return 3;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *indentifier = @"mycell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];
    
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifier];
    }
    
    cell.backgroundColor = [UIColor lightGrayColor];

    if (indexPath.section == 0) {
        
        switch (indexPath.row) {
            case 0:
                cell.textLabel.text = @"艾欧尼亚 电信一";
              
                break;
            case 1:
                cell.textLabel.text = @"祖安 电信二";
                
                break;
            case 2:
                cell.textLabel.text = @"诺克萨斯 电信三";
                
                break;
            case 3:
                cell.textLabel.text = @"班德尔城 电信四";
                
                break;
            case 4:
                cell.textLabel.text = @"皮尔特沃夫 电信五";
                
                break;
            case 5:
                cell.textLabel.text = @"战争学院 电信六";
                
                break;
            case 6:
                cell.textLabel.text = @"巨神峰 电信七";
                
                break;
            case 7:
                cell.textLabel.text = @"雷瑟守备 电信八";
                
                break;
            case 8:
                cell.textLabel.text = @"裁决之地 电信九";
                
                break;
            case 9:
                cell.textLabel.text = @"黑色玫瑰 电信十";
                
                break;
            case 10:
                cell.textLabel.text = @"暗影岛 电信十一";
                
                break;
            case 11:
                cell.textLabel.text = @"钢铁烈阳 电信十二";
                
                break;
            case 12:
                cell.textLabel.text = @"均衡教派 电信十三";
                
                break;
            case 13:
                cell.textLabel.text = @"水晶之痕 电信十四";
                
                break;
            case 14:
                cell.textLabel.text = @"影流 电信十五";
                
                break;
            case 15:
                cell.textLabel.text = @"守望之海 电信十六";
                
                break;
            case 16:
                cell.textLabel.text = @"征服之海 电信十七";
                
                break;
            case 17:
                cell.textLabel.text = @"卡拉曼达 电信十八";
                
                break;
            case 18:
                cell.textLabel.text = @"皮城警戒 电信十九";
                
                break;
            default:
                break;
            
        }
        
        return cell;
    }
    
    if (indexPath.section == 1) {
        
        switch (indexPath.row) {
            case 0:
                cell.textLabel.text = @"比尔吉沃特 网通一";
                break;
            case 1:
                cell.textLabel.text = @"德玛西亚 网通二";
                break;
            case 2:
                cell.textLabel.text = @"弗雷尔卓德 网通三";
                break;
            case 3:
                cell.textLabel.text = @"无畏先锋 网通四";
                break;
            case 4:
                cell.textLabel.text = @"恕瑞玛 网通五";
                break;
            case 5:
                cell.textLabel.text = @"扭曲丛林 网通六";
                break;
            case 6:
                cell.textLabel.text = @"巨龙之巢 网通七";
                break;
            
            default:
                break;
        }
        
        return cell;
    }
    
    if (indexPath.section == 2) {
        
        
        cell.textLabel.text = @"教育网专区 教育一";
        
    }
    
    return cell;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
